#INFO    /HDR/SELF_DIAG/UNI_IO1 (PROGRAM) 11:43 07/31/91
 NAME: UNI_IO1                                    DISK FREE: 10,358,528 BYTES
 DESCRIPTION:                                     SIZE:          16,307 BYTES
                                                  WRITE PROTECT: NO
!**************************************************************************
!* Tests the Vector I/O 1 to 2 (looped by cables)
!* Verifies 40 I/O pins are not open or shorted to adjacent pins
!**************************************************************************

program uni_io1

  declare
    global numeric t1i
    global numeric win2
    persistent numeric cntrl_all
    !string char
    !string iom1 = "/mod1"
    !string iom2 = "/mod2"
    !string iom3 = "/mod3"
    !string iom4 = "/mod4"

    global string clr_scrn = "\1B[2J"
    global string cur_on = "\1B[?25h"
    global string cur_off = "\1B[?25l"
    global string rev = "\1B[7m"
    global string norm = "\1B[0m"
    global string bold = "\1B[1m"
    global string lf_on = "\1B[20h"
    global string lf_off = "\1B[20l"

    global string array [1:4] io_mod
    string mask2 = " "         ! should equal "debug"
    string low_word = "0000000000000000000000000000000000000000"
    string tri_state = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    string result
    string temp_string

    numeric temp_flag                   ! Track Multiple failures
    numeric fflag                        ! Failure Flag to return
    numeric send_pin                     ! counting thru pins 1-40
    numeric rcv_pin                      ! pin 1-40 being checked
    numeric io                           ! step thru Vect. I/O 1 to 4
    numeric temp                         ! temporary storage
    numeric debug_it = 0                 ! set to 1 to run this file

  end declare
! @@@@@@@@@@@@  print Vector I/O shorts/opens  @@@@@@@@@@@@@@@@@@@@@@@

function print_failure(pin_number,io_number,result_string,fail_flag)

  declare
    numeric pin_number          ! signal from Vector I/O #1 to #2,etc
    numeric io_number           ! Vector I/O Module number
    string result_string        ! String indicates 0/1 for 40 pins
    numeric fail_flag           ! indicates type of failure
                                ! 1 = pin shorted to adjacent pin
                                ! 2 = pin 1 to pin 1 open,
                                !     pin 2 to pin 2 open, etc.
    global numeric t1i
    global numeric win2

    numeric temp_no
    string temp_string
    string char

  end declare

    print using "\1B[2J",on win2
    winctl channel win2, position "unhide"

    for x = 1 to 15
      print on win2, "\07"
    next

    print using "\1B[1;2HFAULT:",on win2
    print using "\1B[2;2HVect. I/O error",on win2

    print using "\1B[4;7HVector I/O Wiring Error ...",on win2
    print using "\1B[5;7HMod I/O # to #",on win2,io_number,io_number+1
    print using "\1B[6;7H         \1B[7;12H",on win2

    if (fail_flag = 2) then           ! ** Vector I/O pin open **
       print using "\1B[8;12HPin ?# to Pin ?# is open\1B[9;12H",on win2,pin_number,pin_number
    end if

    if (fail_flag = 1) then               ! ** Adjacent pin shorted  **
      print using "\1B[9;12HPin ?# to shorted to Pin:\1B[10;12H",on win2,pin_number
      for x = 1 to 40
       if (x <> pin_number) then          ! ** Adjacent pins only!     **
         temp_string = mid(result_string,x,1)
         if (temp_string <> "*") then
           temp_no = val (temp_string, 10)
         else
           temp_no = 1                    ! ** Pin pulled to tri-state **
         end if
           if (temp_no > 0) then            ! ** Only print shorts       **
              print using "?#, ",on win2,x
           end if
       end if
      next
    end if                                ! ** end of Adjacent short **

    print using "\1B[13;2HPress any key to exit",on win2
    loop while poll (t1i,"input")
      input on t1i, char
    end loop

    loop until (poll(t1i, "input")) = 1
    end loop

    winctl channel win2, position "hide"

end function
! @@@@@@@@@@@@@@@@@  end - print failures  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function print_info(pin_number,io_number,result_string,fail_flag)

  declare
    numeric pin_number          ! signal from Vector I/O #1 to #2,etc
    numeric io_number           ! Vector I/O Module number
    string result_string        ! String indicates 0/1 for 40 pins
    numeric fail_flag           ! indicates type of failure
                                ! 1 = pin shorted to adjacent pin
                                ! 2 = pin 1 to pin 1 open,
                                !     pin 2 to pin 2 open, etc.
    global numeric t1i
    global numeric win2

    numeric temp_no
    string temp_string
    string char

  end declare

    print using "\1B[2J",on win2
    winctl channel win2, position "unhide"

    for x = 1 to 15
      print on win2, "\07"
    next

    print using "\1B[1;2HFAILURE INFORMATION:",on win2
    print using "\1B[2;2HVect. I/O ",on win2

    print using "\1B[3;2HVector I/O Wiring  ...",on win2
    print using "\1B[4;2HMod I/O # to #",on win2,io_number,io_number+1
    print using "\1B[5;2H         \1B[7;2H",on win2
    print using "\1B[6;2HTesting Pin ?# \1B[8;2H",on win2,pin_number

                 ! ** Vector I/O pin open **
    if (fail_flag = 2) then
     print using "\1B[7;12HPin ?# to Pin ?# is OPEN.\1B[9;12H",on win2,pin_number
    end if

                 ! ** Adjacent pin shorted  **

    if (fail_flag = 1) then
      print using "\1B[9;2HPIN ?#  shorted to pins:\1B[10;2H",on win2, pin_number
      print using "\1B[11;2H?#\1B[13;2H",on win2,result_string
    end if

                 ! ** exit window           **
    print using "\1B[13;2HPRESS any key to exit",on win2
    loop while poll (t1i,"input")
      input on t1i, char
    end loop

    loop until (poll(t1i, "input")) = 1
    end loop

    winctl channel win2, position "hide"

end function
! @@@@@@@@@@@@@@@@  end - print failures  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function print_all(result_string)

  declare
    string result_string        ! String indicates 0/1 for 40 pins
    global numeric t1i
    global numeric win2

    numeric temp_no
    string temp_string
    string char

  end declare

    print using "\1B[2J",on win2
    winctl channel win2, position "unhide"

    for x = 1 to 15
      print on win2, "\07"
    next

    print using "\1B[1;2HFAILURE INFORMATION:",on win2
    print using "\1B[2;2HVect. I/O ",on win2

    print using "\1B[3;2HVector I/O Wiring  ...",on win2
    print using "\1B[4;2H    ",on win2
    print using "\1B[5;2H         \1B[7;2H",on win2
    print using "\1B[6;2H         \1B[8;2H",on win2

                 ! ** Vector I/O pin open **
!    if (fail_flag = 2) then
!     print using "\1B[7;12HPin ?# to Pin ?# is OPEN.\1B[9;12H",on win2,pin_number
!    end if

                 ! ** Adjacent pin shorted  **

!    if (fail_flag = 1) then
!      print using "\1B[9;2HPIN ?#  shorted to pins:\1B[10;2H",on win2, pin_number
      print using "\1B[11;2H?#\1B[13;2H",on win2,result_string
!    end if

                 ! ** exit window           **
    print using "\1B[13;2HPRESS any key to exit",on win2
    loop while poll (t1i,"input")
      input on t1i, char
    end loop

    loop until (poll(t1i, "input")) = 1
    end loop

    winctl channel win2, position "hide"

end function
! @@@@@@@@@@@@@@@@  end - print failures  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


! @@@@@@@@@  Begin - Vector I/O 40 pin Troubleshooting @@@@@@@@@@@@@@@@@@

function diag_vectors

! ***************    initialize flags     ****************************

  declare
    global numeric t1i
    global numeric win2
    global string array [1:4] io_mod

    string result               ! ** CHANGE TO AN ARRAY I/O 1 & 2
    string temp_string

    numeric temp_flag                    ! Track Multiple failures
    numeric fflag                        ! Failure Flag to return
    numeric send_pin                     ! counting thru pins 1-40
    numeric rcv_pin                      ! pin 1-40 being checked
    numeric io                           ! step thru Vect. I/O 1 to 4
    numeric pin_num                      ! Vector I/O pin numbers
    numeric temp                         ! temporary storage
    numeric checksum                     ! pin crc
    numeric t1
    numeric t2

    numeric array[1:40] crc                ! store crc from Vector I/O

  end declare

  fflag = 0
  temp_flag = 0
  t1 = 24977               ! first checksum
  t2 = 49955               ! second checksum
  crc[1] = 17766
  crc[2] = t1
  crc[3] = t2
  crc[4] = t1
  crc[5] = t2
  crc[6] = t1
  crc[7] = t2
  crc[8] = t1
  crc[9] = t2
  crc[10] = t1
  crc[11] = t2
  crc[12] = t1
  crc[13] = t2
  crc[14] = t1
  crc[15] = t2
  crc[16] = t1
  crc[17] = t2
  crc[18] = t1
  crc[19] = t2
  crc[20] = t1
  crc[21] = t2
  crc[22] = t1
  crc[23] = t2
  crc[24] = t1
  crc[25] = t2
  crc[26] = t1
  crc[27] = t2
  crc[28] = t1
  crc[29] = t2
  crc[30] = t1
  crc[31] = t2
  crc[32] = t1
  crc[33] = t2
  crc[34] = t1
  crc[35] = t2
  crc[36] = t1
  crc[37] = t2
  crc[38] = t1
  crc[39] = t2
  crc[40] = t1


! ******************************************************************
! * This routine sends a pattern of alternate one's and zero's from
! * one Vector I/O module to another.  The clock frequency is normally
! * 10 mhz.
! ********************************************************************

! ************   setup Vector I/O Output ************************
!for io = 1 to 3 step 2
 io = 1

  vectorload device io_mod[io], file "uni_mod_io"

  clockfreq (io_mod[io],"10MHz")
  syncoutput (io_mod[io],"intfreq")
  edgeoutput device io_mod[io], start "at_vectordrive"
  enableoutput device io_mod[io], mode "always"


!next                                ! ** for = 1-3, setup I/O modules **

! ************** setup Vector I/O Inputs ******************************
 io = 2

!for io = 2 to 4 step 2
  sync (io_mod[io],"ext")
  edge device io_mod[io], start "+", stop"-", clock "+"
!next
! ************** Drive 1st I/O & Measure second I/O *******************

!for io = 2 to 4 step 2
 !i=2 !** module 1-2 for now
!loop until io  = 10
 arm (io_mod[io])
  vectordrive device io_mod[io -1],startmode"now"
!  loop until ((drivepoll device io_mod[io])) = 3   !

  loop until temp = 15   !** Stop Received   !** should be 15 ????
      temp = checkstatus device io_mod[io]         !** Start Received
                                                    !** Data Clocked
! & count > 100 - ADD

  end loop
 readout (io_mod[io])
!next
! end loop

! ************  check 40 pins for incorrect signature  ****************
 !for io= 2 to 4 step 2               ! ** read receiving I/O modules **

  for pinnum = 1 to 40
     checksum = sig device io_mod[io],pin pinnum

     if (checksum <> crc[pinnum]) then
       fflag = 1

       if (pinnum = 1) then
         result = str(pinnum,10)
       else
         result = result + ", " + str(pinnum,10)
       end if                           ! ** end if pinnum = 1        **
     end if                             ! ** end if crc <> crc[pinnum]**

  next                               ! ** next pinnum

 !next                                ! ** next io number

! if (fflag = 1) then diag_40pin()
 if (fflag = 1) then print_all(result)


end function

! @@@@@@@@@@@@@@@@  end - print failures  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

! @@@@@@@@@@  Begin - Vector I/O 40 pin Troubleshooting @@@@@@@@@@@@@@@@@

function diag_40pin


! ***************    initialize flags     ****************************

  declare
    global numeric t1i
    global numeric win2
    global string array [1:4] io_mod

    string result
    string temp_string

    numeric temp_flag                   ! Track Multiple failures
    numeric fflag                        ! Failure Flag to return
    numeric send_pin                     ! counting thru pins 1-40
    numeric rcv_pin                      ! pin 1-40 being checked
    numeric io                           ! step thru Vect. I/O 1 to 4
    numeric temp                         ! temporary storage
end declare

  fflag = 0
  temp_flag = 0

! ********************************************************************
! *   Set each pin (one at a time) to 1 on /mod1 and measure for open
! *   to same pin on /mod2 , then measure adjacent connections to
! *   verify no shorts (all 0's).
! ********************************************************************

for io = 1 to 3 step 2                 ! ** check Module 1-2,then 3-4

  for send_pin = 1 to 40               ! ** send 1 pin, then check 40 pins

   result = ""
   writepin device io_mod[io], pin send_pin, level "1", mode "latch" ! set pin
   wait (20)
   result = readword device io_mod[io+1], word io+1, mode "now" ! read all pins

   for rcv_pin = 1 to 40
    if (rcv_pin <> send_pin) then
      temp_string = mid (result, rcv_pin, 1)
      if (temp_string <> "*") then
          temp = val (temp_string, 10)
      else
          temp = 1                       ! ** Pulled to tri_state         **
      end if

      if (temp >0) then
              temp_flag = 1
              fflag = 1                  ! ** shorted to adjacent pin     **
              ! add to list of shorts
      end if
    end if

    if (rcv_pin = send_pin) then
      temp_string = mid (result, rcv_pin, 1)
      if (temp_string <> "*") then
         temp = val (temp_string, 10)
      else
         temp = 1                        ! ** Pulled to tri-state         **
      end if

      if (temp < 1) then
              temp_flag = 2
              fflag = 1                  ! ** open pin between Vector I/Os**
      end if
    end if

    if (temp_flag <> 0) then

     ! print_info(send_pin,io,result,temp_flag)
      print_failure(send_pin,io,result,temp_flag)
      ! call print failure routine (pass pin # & result & I/O module #[io])
    end if

    next                               ! ** next Receiving Pin             **

   writepin device io_mod[io], pin send_pin, level "0", mode "latch" ! reset pin

  next                                 ! ** next I/O pin                    **

 next                                  ! ** Vector I/O module 1-2, then 3-4 **

  end function

  ! @@@@@@@@@@@@@@  end - 40 pin Troubleshooting  @@@@@@@@@@@@@@@@@@@@

  ! @@@@@@@@@@@@@@@@@@@  BEGIN MAIN PROGRAM  @@@@@@@@@@@@@@@@@@@@@@@@@

  if (debug_it) then
   crt_win = open device "/term2/win",as "output",mode "unbuffered"
   ! ** Open Test Window **
   win2 = open device "/term2/win",as "output",xorg 30,yorg 9,xdim 48,ydim 15,border ""
   winctl channel win2, position "hide"
   print on win2, cur_off+lf_on+norm
   ! ** Open Keyboard **
   t1i = open device "/term1", as "input", mode "unbuffered"
end if



 ! *****   Vector I/O Module array **********************************

    io_mod[1] = "/mod1"
    io_mod[2] = "/mod2"
    io_mod[3] = "/mod3"
    io_mod[4] = "/mod4"

    io = 1

  ! ****************    *********************

  !****  setup iom1 output  ****
!  syncoutput (iom1, "drclk")
!
!  edgeoutput (iom1, "-", "+", "+")
!  enableoutput (iom1, "high")

  !****  setup iom1 input  ****
!  sync (iom1, "ext")
!  edge (iom1, "-", "+", "+")
!  enable (iom1, "high")


! ****************   Clear Vector I/O Outputs *********************
  setword device io_mod[1], word 1, as_pins "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40"

  setword device io_mod[2], word 2, as_pins "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40"


  setword device io_mod[3], word 3, as_pins "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40"

  setword device io_mod[4], word 4, as_pins "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40"

  writeword device io_mod[1], word 1, patt low_word
  writeword device io_mod[2], word 2, patt tri_state
  writeword device io_mod[3], word 3, patt low_word
  writeword device io_mod[4], word 4, patt tri_state


temp_flag = 10               ! 30 nanosecond clock delay
temp = 1000000 - temp_flag
fflag = setoffset device io_mod[2], offset temp



  diag_vectors()


  if (fflag > 0) then
    return("FAILED")
  else
    return("PASSED")
  endif

if (debug_it) then
   close(crt_win)
   close(win2)
end if

end program





